# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=scipy
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.5.0
pkgrel=1
pkgdesc="SciPy is open-source software for mathematics, science, and engineering (mingw-w64)"
arch=('any')
url="https://www.scipy.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libgfortran"
         "${MINGW_PACKAGE_PREFIX}-openblas"
         "${MINGW_PACKAGE_PREFIX}-python-numpy")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-nose: testsuite")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc-fortran"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/scipy/scipy/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz
        001-build-fix.patch)
sha256sums=('4ff72877d19b295ee7f7727615ea8238f2d59159df0bdd98f91754be4a2767f0'
            '6753ce337da82b660bd4bfc11119e9f79b25ac337c5c146ae1171e795aaca417')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-build-fix.patch

  cd "${srcdir}"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd ${srcdir}/python-build-${CARCH}
  LDFLAGS="${LDFLAGS} -Wall -shared"
  result="fail"
  while [ "$result" = "fail" ]; do
    MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py config_fc --fcompiler=gnu95 build && result="success"
  done
}

package() {
  cd python-build-${CARCH}
  LDFLAGS="${LDFLAGS} -Wall -shared"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py config_fc --fcompiler=gnu95 install \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1  --skip-build

  install -Dm644 LICENSE.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
